/*
 * ComponenteAS.java
 *
 * Created on August 12, 2007, 4:44 PM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package tcc.applicationService.Componente;

import java.util.List;
import tcc.applicationService.AbstractAS;
import tcc.dao.produto.ComponenteDao;
import tcc.exception.TccException;
import tcc.exception.business.TccBusinessException;
import tcc.exception.system.TccASException;
import tcc.exception.system.TccSystemException;
import tcc.util.PersistenceUtil;
import tcc.domain.produto.Componente;

/**
 *
 * @author Diego
 */
public class ComponenteAS extends AbstractAS {
    
    /** Creates a new instance of ComponenteAS */
    private ComponenteAS() {
    }
    private static ComponenteAS instance;
    public static synchronized ComponenteAS getIsntance(){
        if(instance==null){
            instance = new ComponenteAS();
        }
        return instance;
    }
            
    public void saveComponente(Componente c) throws TccBusinessException, TccASException{
        try{
            PersistenceUtil.getInstance().getTransaction().begin();
            ComponenteDao dao = new ComponenteDao();
            dao.save(c);
            PersistenceUtil.getInstance().getTransaction().commit();
        }catch(TccBusinessException ex){
            PersistenceUtil.getInstance().getTransaction().rollback();
            throw ex;
        }catch(TccSystemException ex){
            PersistenceUtil.getInstance().getTransaction().rollback();
            throw new TccASException(ex);
        }
    }
    public List<Componente> findAll(){
        ComponenteDao dao = new ComponenteDao();
        return dao.findAll();
    }
}
